#!/usr/bin/perl 

use strict;
use CGI qw(:all);
use CGI::Carp qw( fatalsToBrowser );


require "./lib/file_engine.cgi";

print "Content-Type: text/html\n\n";

my $script="readm.cgi";

my $all_message;
my $buffer;
my $cgi = new CGI;
my $file = $cgi->param('file');
my $write = $cgi->param('write');
my $user = $cgi->param('user');
my $code = $cgi->param('code');
my $message = $cgi->param('message');
my $user_email = $cgi->param('user_email');
my $start=$cgi->param('start');

my $g_id="007007";

##--------------------------------------------------------------##
#  saving messages.
##--------------------------------------------------------------##

if($message =~/Please\swrite\sdown\syour\smessage\shere/){
print <<EOF;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META HTTP-EQUIV="Refresh" CONTENT="10; URL=./readm.cgi">
</head>
<body>
请认真书写帖子的内容。点击浏览器的返回按钮可以继续修改内容。
</body>
</html>
EOF
exit();

}

if($message  and $code=~/reader/ ){
record_message($g_id,$user,$message,$user_email);
print <<EOF if $message;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META HTTP-EQUIV="Refresh" CONTENT="1; URL=./readm.cgi">
</head>
<body>
Thanks for your message. Continue by <a href="./readm.cgi">click</a>.
</body>
</html>
EOF
exit();
}


##--------------------------------------------------------------##
# reading messages
##--------------------------------------------------------------##
my $header;
open(FH,"<header.txt");
while(<FH>){
	$header.=$_;
}
close(FH);

$all_message=read_message($g_id,$start) if $g_id and not $write ;

$all_message=<<EOF if $all_message;

$header

<div class="message">
$all_message
</div>
<br>
EOF

print <<EOF;

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
 <head>
  <title>Messages</title>
 <LINK REL="stylesheet" HREF="my.css">
 <meta http-equiv="Content-Type"   content="text/html; charset=UTF-8">
<META NAME='KEYWORDS' CONTENT='big file, transfer file, share file, ship it'>
 <META NAME="description" content="Ship it! A system to share/transfer big files among a specified group.">

 </head>
 <body onLoad="swapform();">
<br>


$all_message

<!--
<h3> <a name="post" >Leave your message here.</a>
</h3>
<FORM method="POST" action="./readm.cgi">
Your Name:<br>
 <input type="text" name="user" size="30"><br>
Your email address:<br>
 <input type="text" name="user_email" size="30">(it will not be public to others.)<br>
Verification code:
<br>
 <input type="text" name="code" size="30">
 (Please input "xys-reader" here.)
<br>
 Your message:<br>

<textarea name="message" rows="15" cols="50">Please write down your message here.</textarea><br>

<INPUT type="submit" value="Submit your message to me.">

</FORM>
-->

<br>

Read all messgae 
<a href="./readm.cgi"> Go
</a>
<br>
<br>

</body>
</html>

EOF
